{extend name="public/base"/}
{block name="style"}
<link href="__PUBLIC__/ieasy/css/classify.css?v=2.1.49" rel="stylesheet" type="text/css">
<link href="__PUBLIC__/ieasy/css/book_details.css" rel="stylesheet" type="text/css">
{/block}
{block name="body"}
<div id="console_main"></div>
<div class="head_tit_box">
	<a href="javascript:;" class="head_return_page_but"></a>
		<div class="head_menu_but_box">
		<a href="javascript:;" class="head_menu_but"></a>
	</div>
		<h1>{$title}</h1>
</div>
<!--导航-->
{block name="include"}{include file="public:dropnav" /}{/block}
<!-- 这是正文  -->

<div class="body_sytle">
	<div class="bd_head_box">
		
		<div class="bl_tit_box">
			<div class="directory_select">
				<span></span>
				<select id="book_page">

					
					
				</select>
			</div>
			<strong class="total_chapter">共章</strong>
		</div>
		<div class="cell">
		<div class="bd">
      <div class="weui_cells weui_cells_access" id="catalog-container">
        <div id="catalog-entries"></div>
        <div class="weui-infinite-scroll">
          <div class="infinite-preloader"></div>
        </div>
      </div>
    </div>
</div>
	</div>
	
</div>
<script type="text/html" id="list2">
        <% for(var i = 0; i < data.length; i++){ %>
		<option value="/book/chapter/<%= bid %>?p=<%= data[i]['page']+1 %>" p="<%= data[i]['page']+1 %>" <% if (data[i]['page']+1==p) { %> selected <% } %> ><%= data[i]['title'] %>章</option>
        <% } %>    
</script>


{/block}
{block name="script"}
<script type="text/javascript" src="__PUBLIC__/ieasy/js/zepto.min.js?v=2.1.49"></script>
<script type="text/javascript" src="__PUBLIC__/ieasy/js/zepto.cookie.min.js?v=2.1.49"></script>

<!-- 这是zepto插件 -->

<script type="text/javascript" src="__PUBLIC__/ieasy/js/common.js?v=2.1.49"></script>
<script type="text/javascript" src="__PUBLIC__/ieasy/js/cps_log.js?v=2.1.49"></script>

<!-- 这里引入js -->
<script type="text/javascript">
$(function(){
	$('.bd_description_box a').click(function(){
		$(this).parent().removeClass('bd_description_open');
	});
	$("#book_page").change(function(){
		var url = $(this).val();
		window.location.href=url;
	})
});
</script>

<link rel="stylesheet" href="__PUBLIC__/ieasy/css/front.css" />
<link rel="stylesheet" href="__PUBLIC__/ieasy/css/vendor.css" />
<link href="__PUBLIC__/ieasy/css/font_apds0v8n2bhp8pvi.css" rel="stylesheet">
<script src="__PUBLIC__/ieasy/js/vendor.js"></script>
<script src="__PUBLIC__/ieasy/js/app.js"></script>
<script>
  $(function () {
    var loading = false;
    var nid = {$id};
    var cursor = 0;
    var completed = false;
    var from = '';
    var isForceFollow = false;
    var forceFollowChapterIdx = 6;
    var memberSubscribed = 0;
    var isFree = false;
    var p={$page};
    var limit=101;

    //f2f6f1e429ba0ab55046591a99e71868
    loadCatalogEntries(nid, cursor);

    $(document.body).infinite(50).on('infinite', function () {
      if (loading || completed) {
        return false;
      }

      loadCatalogEntries(nid, cursor);
    });

    return $.get('/api/novel/getchapternum/', {bookid: nid,num:100}, function (data) {
    			data.p=p;
    			data.bid=nid;
                var banner=template('list2',data);
                document.getElementById("book_page").innerHTML = banner;
                $('.total_chapter').html('共'+data.count+'章');

        });

    function loadCatalogEntries(nid, start) {
      loading = true;
      start=(p-1)*(limit-1);
      return $.get('/api/novel/getchater/', {bid: nid,start: start,limit:limit-1}, function (result) {
        var entries = result.data;
        var htmls = [];
        $.each(entries, function () {
          var entry = this;

          entry.title = entry.title || '第' + entry.idx + '章';
          entry.welth = parseInt(entry.isvip);

          var badges = [];

          if (entry.welth > 0) {
            if (isFree) {
              badges.push('<span style="color:orangered;font-size:13px;">限免</span>');
            } else {
              badges.push('<span style="color:hotpink;"><i class="iconfont icon-diamond" style="vertical-align:middle"></i><span style="vertical-align:middle;font-size:16px;padding-left:2px;display:none">' + entry.welth + '</span></span>');
            }
          }

          var followRequried = isForceFollow && entry.idx >= forceFollowChapterIdx && !memberSubscribed;

          var url = followRequried ? 'javascript:;' : entry.link;
          var style = followRequried ? 'color:#aaa' : '';

          htmls.push(
              '<a class="weui_cell" href="' + url + '" style="' + style + '">' +
              '<div class="weui_cell_bd weui_cell_primary">' +
              '<p>' +
              entry.title + ' ' + badges.join('') +
              '</p>' +
              '</div>' +
              '</a>'
          );
        });

        $('#catalog-entries').append(htmls.join(''));

        cursor = cursor + entries.length;
        completed = entries.length === 0;
        loading = false;

        //if (completed) {
          $(document.body).destroyInfinite();//f2f6f1e429ba0ab55046591a99e71868
          $('.weui-infinite-scroll').remove();
      //  }
      });


    }
  });
</script>
{/block}